{% load shop_currency %}
{% if request.cart.items %}
    <table summary="The contents of your shopping cart">
        <thead>
            <tr>
                <th class="cart-item">Item</th>
                <th>Quantity</th>
                <th>Item Price</th>
                <th>Total Price</th>
            </tr>
        </thead>
        <tfoot>
            <tr>
                <td></td>
                <td class="cart-quantity">
                    <form method="post" action="{% url shop.views.cart.clear %}" class="clear-cart-form">
                        {% csrf_token %}
                        <div><button type="submit">Empty Cart</button></div>
                    </form>
                </td>
                <td></td>
                <td class="cart-price">{{ request.cart.total_price|currency }}</td>
            </tr>
        </tfoot>
        <tbody>
        {% for item in request.cart.items %}
            <tr>
                <td class="cart-item"><a href="{% url shop.views.product.detail item.product.id %}">{{ item.product.name }}</a></td>
                <td class="cart-quantity">
                    <form action="{% url shop.views.cart.update item.product.id %}" method="post" class="product-quantity-form">
                        {% csrf_token %}
                        <div>
                            <input type="text" name="quantity" maxlength="3" value="{{ item.quantity }}" class="product-quantity"/>
                        </div>
                        <noscript>
                            <div><button type="submit">Update</button></div>
                        </noscript>
                    </form>
                    <form action="{% url shop.views.cart.remove item.product.id %}" method="post" class="product-remove-form">
                        {% csrf_token %}
                        <div><button type="submit">Remove</button></div>
                    </form>
                </td>
                <td class="cart-price">{{ item.product.price|currency }}</td>
                <td class="cart-price">{{ item.total_price|currency }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <ul class="actions">
        <li>
            <form method="get" action="{% url shop.views.checkout.show %}">
                <div><button type="submit">Check Out</button></div>
            </form>
        </li>
        <li>
            <form method="get" action="{% url shop.views.product.list %}">
                <div><button type="submit">Continue Shopping</button></div>
            </form>
        </li>
    </ul>
{% else %}
    <p>The shopping cart is empty.</p>

    <ul class="actions">
        <li>
            <form method="get" action="{% url shop.views.product.list %}">
                <div><button type="submit">Continue Shopping</button></div>
            </form>
        </li>
    </ul>
{% endif %}
